import time

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

options = webdriver.ChromeOptions
options.binary_location = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
browser = webdriver.Chrome(executable_path="F:\Chromedriver\chromedriver")
browser.maximize_window()
browser.get(str("http://127.0.0.1"))
login_name = browser.find_element_by_id('username')
login_psw = browser.find_element_by_id('userp')
login_button = browser.find_element_by_id('submitbtn')
login_name.send_keys('admin')
login_psw.send_keys('admin')
login_button.click()
time.sleep(3)
menuBar = browser.find_element_by_xpath('/html/body/div[1]/aside/section/div/ul/li[3]/a/span').click()
time.sleep(2)
deviceBar = browser.find_element_by_xpath('/html/body/div[1]/aside/section/div/ul/li[3]/ul/li[1]/a').click()
time.sleep(2)
addDevice = browser.find_element_by_xpath('//*[@id="GroupList"]/tbody/tr[1]/td[7]/div[2]/a[1]').click()
time.sleep(2)

#frameName = browser.find_element_by_class_name('iframe-info')
frameId = browser.find_element_by_xpath('//body/div[1]/div[3]/section[1]/div[1]/div[2]/div[3]/div[6]/iframe[1]')
realFrame = frameId.find_element_by_xpath('//body/div[1]/div[3]/section[1]/div[1]/div[2]/div[3]/div[6]/iframe[1]')
time.sleep(2)
#move = browser.find_element_by_xpath('//div[contains(text(),"物联网")]' and '//body/div[1]/div[3]/section[1]/div[1]/div[2]/div[3]/div[6]/iframe[1]').click()
#move = browser.find_element_by_xpath('/html[1]/body[1]/div[1]/div[1]/div[1]/div[7]/div[1]').click()
#ActionChains(browser).move_to_element(move).perform()
try:
    move = realFrame.find_element_by_xpath('//div[contains(text(),"物联网")]' and '//body/div[1]/div[3]/section[1]/div[1]/div[2]/div[3]/div[6]/iframe[1]')
    x = move.location.get('x')
    y = move.location.get('y')
    print(x,y)
except:
    print("error")

ActionChains(browser).click(move).perform()

time.sleep(2)


#UPSDevice = browser.find_element_by_xpath('//body[1]/div[1]/div[1]/div[2]/div[7]/div[2]/div[4]/table[1]/tbody[1]/tr[1]/td[2]/div[1]').click()


